package org.example.task;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * @Author wangf
 * @Description 封装连接类
 * @Date 2023/3/2 16:33
 */
public class ConnectElasticsearch {
    public static void  connect(ElasticsearchTask task){
        //创建客户端对象 并自动关闭链接
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost",9400,"http")));
        try {
            task.doSomething(client);
            client.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
